package hongvt.quanlynhanvien.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.widget.TextView;

public class StringUtils {

	/**
	 * checking empty of string object
	 * 
	 * @param stringForCheck
	 * @return false if string is null or trimming string is empty true with
	 *         other case
	 */
	public static boolean isEmpty(String stringForCheck) {
		if (stringForCheck == null)
			return true;
		if (stringForCheck.trim().equals(""))
			return true;
		return false;
	}

	/**
	 * checking empty of text in textview
	 * 
	 * @param textView
	 * @return false if text of textview is null or trimming string is empty
	 *         true with other case
	 */
	public static boolean isEmpty(TextView textView) {
		return isEmpty(textView.getText().toString());
	}

	/**
	 * convert string with MD5 encryption
	 * 
	 * @param str
	 *            string to encryption
	 * @return string when encrypted
	 */
	public static String encodeMD5(String str) {
		String hashword = null;
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(str.getBytes());
			BigInteger hash = new BigInteger(1, md5.digest());
			hashword = hash.toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return hashword;
	}
}
